package com.rmb.dataanalysis.client;

import com.rmb.dataanalysis.service.impl.DataAnalysisHyxstrixImpl;
import com.rmb.entity.SourceEntity;
import com.rmb.fremarker.client.RmbServiceFeign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author ZhaoMuYang
 * @Date 2021/1/11 15:19
 */
@FeignClient(name = RmbServiceFeign.RMB_DATASOURCE,fallback = DataAnalysisHyxstrixImpl.class)
public interface DataSourceServiceClient {

    /**
     * 获取数据源
     * @return 数据源集合
     */
    @GetMapping("/rmb/source/getAllDataSource")
    List<Map<String,Object>> getAllDataSource();


    /**
     * 获取指定数据源所属数据库
     * @param dataSourceId 数据源ID
     * @return 数据库
     */
    @GetMapping("/rmb/source/getAllDataBase/{dataSourceId}")
    List<String> findAllDataBase(@PathVariable("dataSourceId") Long dataSourceId);

    /**
     * 获取指定数据源所有表
     * @param dataCourseId 数据源ID
     * @param dataBaseName  数据库名称
     * @return 表集合
     */
    @GetMapping("/rmb/source/getTablesByDataSource")
    List<String> findTablesByDataSource(@RequestParam("dataSourseId")Long dataCourseId,
                                               @RequestParam("dataBaseName")String dataBaseName);


    /**
     * 执行sql语句
     * @param dataSourceId 数据源ID
     * @param dataBaseName 数据库名称
     * @param tableName 表名称
     * @param sql sql语句
     * @return 查询结果
     */
    @GetMapping("/rmb/source/executeSqlQuery")
    List<Map<String,Object>> executeSqlQuery(@RequestParam("dataSourceId") Long dataSourceId,
                                             @RequestParam("dataBaseName") String dataBaseName,
                                             @RequestParam("tableName") String tableName,
                                             @RequestParam("sql") String sql);

    /**
     * 获取指定数据源
     * @param dataSourceId 数据源ID
     * @return
     */
    @GetMapping("/rmb/source/getDataSourceById/{dataSourceId}")
    public SourceEntity getDataSourceById(@PathVariable("dataSourceId")Long dataSourceId);

}
